﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;

namespace ResUma
{
    public partial class TipPrezentaFrm : FrmCard
    {
        public TipPrezentaFrm(ModuleClass mInfo)
            : base(mInfo)
        {
            InitializeComponent();
            sexSursaBindingSource.List.Add(new SexSursa("Ore", 0, "O"));
            sexSursaBindingSource.List.Add(new SexSursa("Zile", 1, "Z"));
            sexSursaBindingSource.List.Add(new SexSursa("Valoare", 2, "V"));

            tipPrezBindingSource.List.Add(new FormatTipSpor("Prezenta", "P"));
            tipPrezBindingSource.List.Add(new FormatTipSpor("Concediu Odihna", "O"));
            tipPrezBindingSource.List.Add(new FormatTipSpor("Nemotivate", "N"));
            tipPrezBindingSource.List.Add(new FormatTipSpor("Altele", "X"));

            this.HandleRezumat += TipPrezentaFrm_HandleRezumat;

            eSRPDataSet.TipPrezenta.InclusCASColumn.DefaultValue = true;
            eSRPDataSet.TipPrezenta.ProcentBazaColumn.DefaultValue = 0;
            eSRPDataSet.TipPrezenta.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            eSRPDataSet.TipPrezenta.IdOpContabilaColumn.DefaultValue = 0;
            eSRPDataSet.TipPrezenta.SelectatColumn.DefaultValue = true;
            eSRPDataSet.TipPrezenta.SeListeazaColumn.DefaultValue = true;
        }

        void TipPrezentaFrm_HandleRezumat(object sender, EventArgs e)
        {
            Int32 selID = -1;
            if (tipPrezentaBindingSource.Current != null)
            {
                ESRPDataSet.TipPrezentaRow prr = ((DataRowView)tipPrezentaBindingSource.Current).Row as ESRPDataSet.TipPrezentaRow;
                selID = (Int32)prr.IdTipPrezenta;
            }
            TipPrezentaRezumatFrm frm = new TipPrezentaRezumatFrm(ModuleInfo,selID);
            frm.SelectionAddOn = true;
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (frm.selectedDataRow != null)
                {
                    tipPrezentaBindingSource.RemoveFilter();
                    ESRPDataSet.TipPrezentaRow pr = frm.selectedDataRow.Row as ESRPDataSet.TipPrezentaRow;
                    try
                    {
                        tipPrezentaBindingSource.EndEdit();
                    }
                    catch (Exception)
                    {
                        tipPrezentaBindingSource.CancelEdit();
                    }
                    tipPrezentaBindingSource.Position = tipPrezentaBindingSource.Find("IDTipPrezenta", pr.IdTipPrezenta);
                    tipPrezentaBindingSource.ResetCurrentItem();
                    SetTitle();
                }
            }
            EnableMainBrowseButton = true;
        }

        private void TipPrezentaFrm_Load(object sender, EventArgs e)
        {
            this.tipPrezentaTableAdapter.Connection = DeschideConexiune(workConnString);
            this.tipPrezentaTableAdapter.Fill(this.eSRPDataSet.TipPrezenta,ModuleInfo.CodUnitate);
            InchideConexiune(this.tipPrezentaTableAdapter.Connection);

            this.listBndSourceMain.Add(tipPrezentaBindingSource);
            listTableAdaptor.Add(this.tipPrezentaTableAdapter.Adapter);

            if (tipPrezentaBindingSource.Count == 0)
                tipPrezentaBindingSource.AddNew();
        }
    }
}
